import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-11-13
 * Time: 8:59
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++){
            int n = in.nextInt();
            PriorityQueue<Integer> minHeap = new PriorityQueue<>();
            for (int j = 0; j < n; j++) {
                int type = in.nextInt();
                switch (type){
                    case 1:
                        minHeap.offer(in.nextInt());
                        break;
                    case 2:
                        System.out.println(minHeap.poll());
                        break;
                }
            }
        }
    }
}
